Object may be Not Finalized (ONF)

Description:

In the case of an exception, an object will not be released if a method is placed in a finally block in one piece of the code but is also used outside of the finally clause in some places where an exception can also be raised.

ONF does not understand the semantics of the method and cannot determine whether the method is really releasing or closing some resource, but if it is used somewhere inside of a finally block, then it means that invocation of this method is critical and should be done in any case. Therefore, if in some other place where exceptions are also possible (the method is declared as throwing some exception or it is a statement in a try block), and the method is used outside of the finally block, it can be an error.

Incorrect:

procedure read(resource:IResource;buf:array of char);
begin
    resource.open();
    try
        ...
    finally
        resource.close();
    end;
end;

procedure write(resource:IResource;buf:array of char); 
begin
    resource.open();
    ...
    resource.close();
end;

Correct:

procedure write(resource:IResource;buf:array of char); 
begin
    try
        ...
    finally
        resource.close();
    end;
end;